package com.cat.chapter046;
import java.io.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Arrays;

/**
 * @author cat
 * @description https://www.nowcoder.com/practice/36fb0fd3c656480c92b569258a1223d5
 * @create 2025/7/15 13:39
 * @since JDK17
 */

public class Solution01 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer tokenizer = new StreamTokenizer(br);
    static long n, m, k, sum;
    static long[] arr = new long[100001];
    static HashMap<Long, Integer> map = new HashMap<>();
    static int ans;

    public static void main(String[] args) throws IOException {
        map.clear();
        tokenizer.nextToken();
        n = ((long) tokenizer.nval);
        tokenizer.nextToken();
        k = ((int) tokenizer.nval);
        sum = 0;
        map.put(0L, 0);
        ans = -1;
        for (int i = 0; i < n; i++) {
            tokenizer.nextToken();
            arr[i] = ((int) tokenizer.nval);
            sum = sum + arr[i]; // 求前缀和
            if (map.containsKey(sum - k)) {   // 如果找到了就加入map中
                ans = Math.max(ans, i + 1 - map.get(sum - k));
            }
            if (!map.containsKey(sum)) {  // 不包含就添加进去
                map.put(sum, i + 1);
            }
        }
        pr.println(ans);
        pr.flush();
        pr.close();
        br.close();
    }
}
